package com.yugao.fintech.antelope.mps.model;

import com.yugao.fintech.antelope.mps.api.constatnts.ChannelTypeEnum;
import com.yugao.fintech.antelope.mps.model.entity.MsgReceiver;
import com.yugao.fintech.framework.assistant.utils.StringUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 接收者配置信息

 */
@Data
public class ReceiverConfig {
    private ChannelTypeEnum channelType;
    private String toUser;

    public static List<ReceiverConfig> of(MsgReceiver msgReceiver) {
        List<ReceiverConfig> list = new ArrayList<>();

        if (StringUtils.isNotEmpty(msgReceiver.getPhone()) && Objects.equals(msgReceiver.getPhoneStatus(), MsgReceiver.Status.VERIFY)) {
            ReceiverConfig resp = new ReceiverConfig();
            resp.setChannelType(ChannelTypeEnum.SMS);
            resp.setToUser(msgReceiver.getPhone());
            list.add(resp);
        }

        if (StringUtils.isNotEmpty(msgReceiver.getEmail()) && Objects.equals(msgReceiver.getEmailStatus(), MsgReceiver.Status.VERIFY)) {
            ReceiverConfig resp = new ReceiverConfig();
            resp.setChannelType(ChannelTypeEnum.EMAIL);
            resp.setToUser(msgReceiver.getEmail());
            list.add(resp);
        }

        if (StringUtils.isNotEmpty(msgReceiver.getWxMpOpenId())) {
            ReceiverConfig resp = new ReceiverConfig();
            resp.setChannelType(ChannelTypeEnum.WX_MP);
            resp.setToUser(msgReceiver.getWxMpOpenId());
            list.add(resp);
        }
        return list;
    }
}
